<?php
	include ('../Includes/Header.php');
	include ('../Includes/DBConn.php'); 
	
	$klasse_array = $_POST['klasse'];
	$lehrer_array = $_POST['lehrer'];
	
	echo "INPUT.Klasse: ".$klasse_array[0]."<br />";
	echo "INPUT.Lehrer: ".$lehrer_array[0]."<br />";

	$id_klasse;
	$id_lehrer;
	
	$sql="SELECT ID FROM klasse WHERE bez='$klasse_array[0]';";
	$result = mysql_query($sql);
	#$count = mysql_num_rows($result);
	while($row=mysql_fetch_assoc($result)) {
		foreach ($row as $value) {
			echo "ID.Klasse: ".$value."<br />";
			$id_klasse=$value;
		}
	}
	
	$sql="SELECT ID FROM lehrer WHERE nname='$lehrer_array[0]';";
	$result = mysql_query($sql);
	#$count = mysql_num_rows($result);
	
	while($row=mysql_fetch_assoc($result)){
		foreach ($row as $value) {
			echo "ID.Lehrer: ".$value."<br />";
			$id_lehrer=$value;
		}
	}
	

	if ($lehrer_array[0]=='Alle' && $klasse_array[0]=='Alle') {
		$sql="SELECT alehrer, vlehrer, klasse, stunde, datum, information, buser, bdatum FROM vertretung
			  ORDER BY datum;";
		echo $sql;
	}
	
	if (!($lehrer_array[0]=='Alle') && $klasse_array[0]=='Alle') {
		$sql="SELECT alehrer, vlehrer, klasse, stunde, datum, information, buser, bdatum FROM vertretung 
			  WHERE alehrer='$id_lehrer' ORDER BY datum;";
		echo $sql;
	}
	
	if ($lehrer_array[0]=='Alle' && !($klasse_array[0]=='Alle')) {
		$sql="SELECT alehrer, vlehrer, klasse, stunde, datum, information, buser, bdatum FROM vertretung 
			  WHERE klasse='$id_klasse' ORDER BY datum;";
		echo $sql;
	}
	
	if (!($lehrer_array[0]=='Alle') && !($klasse_array[0]=='Alle')) {
		$sql="SELECT alehrer, vlehrer, klasse, stunde, datum, information, buser, bdatum FROM vertretung 
			  WHERE alehrer='$id_lehrer' AND klasse='$id_klasse' ORDER BY datum;";
		echo $sql;
	}


?>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="../../CSS/stylesheet.css">
	</head>
	<body>
		
		<form>
			<input type="submit" formaction="../Startseite/Startseite.php" value="Back" name="back">
		</form> 
		<div>
		    <?php
				include '../Includes/DBConn.php';
				$result = mysql_query($sql);
				$count = mysql_num_rows($result);
		
				while($row = mysql_fetch_array($result)) {	#assoc liefert ein assoziatives array zurück während array 2 arrays zurück liefert
				
				?>
				<table border="1">
				    <thead>
				        <tr bgcolor="C0C0C0">
				            <td>alehrer</td>
				            <td>vlehrer</td>
				            <td>klasse</td>
				            <td>stunde</td>
				            <td>datum</td>
				            <td>information</td>
				            <td>buser</td>
				            <td>bdatum</td>
				        </tr>
				    </thead>
				    	<tbody>
							<tr>
				                <td><?php echo $row['alehrer']?></td>
				                <td><?php echo $row['vlehrer']?></td>
				                <td><?php echo $row['klasse']?></td>
				                <td><?php echo $row['stunde']?></td>
				                <td><?php echo $row['datum']?></td>
				                <td><?php echo $row['information']?></td>
				                <td><?php echo $row['buser']?></td>
				                <td><?php echo $row['bdatum']?></td>
				            </tr>
				        <p>&nbsp;</p>
				        <?php
							}
						?>
					</tbody>
				</table>
		<form>
			<input type="submit" formaction="../Startseite/Startseite.php" value="Back" name="back">
		</form> 
		</div>
	</body>
</html>
